<template>
  <div class="app-container">
    <!-- 添加或修改提现管理对话框 -->
    <el-form ref="form" :model="form" :rules="rules" label-width="300px">
      <el-form-item label="默认收益获取比例（%）" prop="incomeRatio">
        <el-input-number :min="0" :max="100" controls-position="right" v-model="form.incomeRatio"
                         placeholder="请输入默认收益获取比例（%）" style="width: 200px"
        />
      </el-form-item>
      <el-form-item label="穿山甲收益获取比例（%）" prop="incomeRatioCsj">
        <el-input-number :min="0" :max="100" controls-position="right" v-model="form.incomeRatioCsj"
                         placeholder="请输入穿山甲收益获取比例（%）" style="width: 200px"
        />
      </el-form-item>
      <el-form-item label="优量汇收益获取比例（%）" prop="incomeRatioYlh">
        <el-input-number :min="0" :max="100" controls-position="right" v-model="form.incomeRatioYlh"
                         placeholder="请输入优量汇收益获取比例（%）" style="width: 200px"
        />
      </el-form-item>
      <el-form-item label="快手收益获取比例（%）" prop="incomeRatioKs">
        <el-input-number :min="0" :max="100" controls-position="right" v-model="form.incomeRatioKs"
                         placeholder="请输入快手收益获取比例（%）" style="width: 200px"
        />
      </el-form-item>
      <el-form-item label="百青藤收益获取比例（%）" prop="incomeRatioBqt">
        <el-input-number :min="0" :max="100" controls-position="right" v-model="form.incomeRatioBqt"
                         placeholder="请输入百青藤收益获取比例（%）" style="width: 200px"
        />
      </el-form-item>
      <el-form-item label="代理人获取收益比例（%）" prop="incomeRatioDlr">
        <el-input-number :min="0" :max="100" controls-position="right" v-model="form.incomeRatioDlr"
                         placeholder="请输入代理人获取收益比例（%）" style="width: 200px"
        />
      </el-form-item>
      <el-form-item label="推荐人获取收益比例（%）" prop="incomeRatioTjr">
        <el-input-number :min="0" :max="100" controls-position="right" v-model="form.incomeRatioTjr"
                         placeholder="请输入推荐人获取收益比例（%）" style="width: 200px"
        />
      </el-form-item>
      <el-form-item label="总代收益比例（%）" prop="incomeRatioBtjthdl">
        <el-input-number :min="0" :max="100" controls-position="right" v-model="form.incomeRatioBtjthdl"
                         placeholder="请输入被推荐用户代理收益比例（%）" style="width: 200px"
        />
      </el-form-item>
      <el-form-item label="ECPM上限金额（元）" prop="ecpmMax">
        <el-input-number :min="0" controls-position="right" v-model="form.ecpmMax" placeholder="请输入ECPM上限金额（元）"
                         style="width: 200px"
        />
      </el-form-item>
<!--      <el-form-item label="代理每天最多出包数量" prop="pkgCnt">
        <el-input-number :min="0" controls-position="right" v-model="form.pkgCnt"
                         placeholder="请输入代理每天最多出包数量" style="width: 200px"
        />
      </el-form-item>-->
      <el-form-item label="代理提现最低金额（元）" prop="minWithdrawMoney">
        <el-input-number :min="0.1" controls-position="right" v-model="form.minWithdrawMoney"
                         placeholder="请输入代理提现最低金额（元）" style="width: 200px"
        />
      </el-form-item>
      <el-form-item label="免审金额（元）" prop="msMoney">
        <el-input-number :min="0" controls-position="right" v-model="form.msMoney"
                         placeholder="不超过当前金额免审核" style="width: 200px"
        />
      </el-form-item>
<!--      <el-form-item label="奖励出现比例（%）" prop="awardRatio">
        <el-input-number :min="0" :max="100" controls-position="right" v-model="form.awardRatio"
                         placeholder="请输入奖励出现比例（%）" style="width: 200px"
        />
      </el-form-item>-->
<!--      <el-form-item label="一个应用一个月最大激励广告收益金额（元）" prop="jlggMoney">
        <el-input-number :min="0" controls-position="right" v-model="form.jlggMoney"
                         placeholder="请输入一个应用一个月最大激励广告收益金额（元）" style="width: 200px"
        />
      </el-form-item>-->
      <el-form-item label="是否启用风控" prop="isFk" size="small">
        <el-radio-group v-model="form.isFk">
          <el-radio-button label="启用"></el-radio-button>
          <el-radio-button label="不启用"></el-radio-button>
        </el-radio-group>
      </el-form-item>
<!--      <el-form-item label="QQ群号码" prop="qqNum">
        <el-input v-model="form.qqNum" placeholder="请输入QQ群号码" style="width: 200px"/>
      </el-form-item>
      <el-form-item label="QQ群介绍文字" prop="qqDetails">
        <el-input v-model="form.qqDetails" placeholder="请输入QQ群介绍文字" style="width: 200px"/>
      </el-form-item>-->
      <el-form-item label="一个手机单个APP每日最大视频数量" prop="phoneCnt">
        <el-input-number :min="0" controls-position="right" v-model="form.phoneCnt"
                         placeholder="请输入一个手机单个APP每日最大视频数量" style="width: 200px"
        />
      </el-form-item>
      <el-form-item label="一个微信单个APP每日最大视频数量" prop="wxVideoCnt">
        <el-input-number :min="0" controls-position="right" v-model="form.wxVideoCnt"
                         placeholder="请输入一个微信单个APP每日最大视频数量" style="width: 200px"
        />
      </el-form-item>
      <el-form-item label="一个IP单个APP每日最大视频数量" prop="ipVideoCnt">
        <el-input-number :min="0" controls-position="right" v-model="form.ipVideoCnt"
                         placeholder="请输入一个IP单个APP每日最大视频数量" style="width: 200px"
        />
      </el-form-item>
      <el-form-item label="一个WIFI单个APP每日最大视频数量" prop="wifiVideoCnt">
        <el-input-number :min="0" controls-position="right" v-model="form.wifiVideoCnt"
                         placeholder="请输入一个WIFI单个APP每日最大视频数量" style="width: 200px"
        />
      </el-form-item>
      <el-form-item label="一个微信号一天最多允许几台手机登录" prop="wxPhoneCnt">
        <el-input-number :min="0" controls-position="right" v-model="form.wxPhoneCnt"
                         placeholder="请输入一个微信号一天最多允许几台手机登录" style="width: 200px"
        />
      </el-form-item>
      <el-form-item label="一个IP一天最多允许几台手机" prop="ipPhoneCnt">
        <el-input-number :min="0" controls-position="right" v-model="form.ipPhoneCnt"
                         placeholder="请输入一个IP一天最多允许几台手机" style="width: 200px"
        />
      </el-form-item>
      <el-form-item label="一个WIFI一天最多允许几台手机" prop="wifiPhoneCnt">
        <el-input-number :min="0" controls-position="right" v-model="form.wifiPhoneCnt"
                         placeholder="请输入一个WIFI一天最多允许几台手机" style="width: 200px"
        />
      </el-form-item>
      <el-form-item label="ECPM最低值" prop="ecpmMin">
        <el-input-number controls-position="right" v-model="form.ecpmMin" placeholder="请输入ECPM最低值"
                         style="width: 200px"
        />
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button type="primary" size="mini" @click="submitForm" style="margin-left: 200px;margin-top: 50px">修改
      </el-button>
    </div>
  </div>
</template>

<script>
import { getIncomeConfig, updateIncomeConfig } from '@/api/income/config'

export default {
  name: 'income',
  data() {
    return {
      // 遮罩层
      loading: true,
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        incomeRatio: [
          { required: true, trigger: 'blur', message: '请输入默认收益获取比例（%）' }
        ],
        incomeRatioDlr: [
          { required: true, trigger: 'blur', message: '请输入代理人获取收益比例（%）' }
        ],
        incomeRatioTjr: [
          { required: true, trigger: 'blur', message: '请输入推荐人获取收益比例（%）' }
        ],
        incomeRatioBtjthdl: [
          { required: true, trigger: 'blur', message: '请输入被推荐用户代理收益比例（%）' }
        ],
        ecpmMax: [
          { required: true, trigger: 'blur', message: '请输入ECPM上限金额（元）' }
        ],
        minWithdrawMoney: [
          { required: true, trigger: 'blur', message: '请输入代理提现最低金额' }
        ],
        isFk: [
          { required: true, trigger: 'change', message: '请输入是否启用风控' }
        ]/* ,
        qqNum: [
          { required: true, trigger: 'change', message: '请输入QQ群号码' }
        ],
        qqDetails: [
          { required: true, trigger: 'change', message: '请输入QQ群介绍文字' }
        ] */
      }
    }
  },
  created() {
    this.IncomeConfig()
  },
  methods: {
    /** 获取收益信息 */
    IncomeConfig(row) {
      this.reset()
      getIncomeConfig().then(response => {
        this.form.id = response.data.id;
        this.form.incomeRatio = response.data.incomeRatio == null ? undefined : response.data.incomeRatio;
        this.form.incomeRatioCsj = response.data.incomeRatioCsj == null ? undefined : response.data.incomeRatioCsj;
        this.form.incomeRatioYlh = response.data.incomeRatioYlh == null ? undefined : response.data.incomeRatioYlh;
        this.form.incomeRatioKs = response.data.incomeRatioKs == null ? undefined : response.data.incomeRatioKs;
        this.form.incomeRatioBqt = response.data.incomeRatioBqt == null ? undefined : response.data.incomeRatioBqt;
        this.form.incomeRatioDlr = response.data.incomeRatioDlr == null ? undefined : response.data.incomeRatioDlr;
        this.form.incomeRatioTjr = response.data.incomeRatioTjr == null ? undefined : response.data.incomeRatioTjr;
        this.form.incomeRatioBtjthdl = response.data.incomeRatioBtjthdl == null ? undefined : response.data.incomeRatioBtjthdl;
        this.form.ecpmMax = response.data.ecpmMax == null ? undefined : response.data.ecpmMax;
        this.form.pkgCnt = response.data.pkgCnt == null ? undefined : response.data.pkgCnt;
        this.form.minWithdrawMoney = response.data.minWithdrawMoney == null ? undefined : response.data.minWithdrawMoney;
        this.form.msMoney = response.data.msMoney == null ? undefined : response.data.msMoney;
        this.form.awardRatio = response.data.awardRatio == null ? undefined : response.data.awardRatio;
        this.form.jlggMoney = response.data.jlggMoney == null ? undefined : response.data.jlggMoney;
        this.form.isFk = response.data.isFk == null ? undefined : response.data.isFk;
        // this.form.qqNum = response.data.qqNum == null ? undefined : response.data.qqNum;
        // this.form.qqDetails = response.data.qqDetails == null ? undefined : response.data.qqDetails;
        this.form.phoneCnt = response.data.phoneCnt == null ? undefined : response.data.phoneCnt;
        this.form.wxVideoCnt = response.data.wxVideoCnt == null ? undefined : response.data.wxVideoCnt;
        this.form.ipVideoCnt = response.data.ipVideoCnt == null ? undefined : response.data.ipVideoCnt;
        this.form.wifiVideoCnt = response.data.wifiVideoCnt == null ? undefined : response.data.wifiVideoCnt;
        this.form.wxPhoneCnt = response.data.wxPhoneCnt == null ? undefined : response.data.wxPhoneCnt;
        this.form.ipPhoneCnt = response.data.ipPhoneCnt == null ? undefined : response.data.ipPhoneCnt;
        this.form.wifiPhoneCnt = response.data.wifiPhoneCnt == null ? undefined : response.data.wifiPhoneCnt;
        this.form.ecpmMin = response.data.ecpmMin == null ? undefined : response.data.ecpmMin;
      })
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        incomeRatio: undefined,
        incomeRatioCsj: undefined,
        incomeRatioYlh: undefined,
        incomeRatioKs: undefined,
        incomeRatioBqt: undefined,
        incomeRatioDlr: undefined,
        incomeRatioTjr: undefined,
        incomeRatioBtjthdl: undefined,
        ecpmMax: undefined,
        pkgCnt: undefined,
        minWithdrawMoney: undefined,
        msMoney: undefined,
        awardRatio: undefined,
        jlggMoney: undefined,
        isFk: undefined,
        // qqNum: undefined,
        // qqDetails: undefined,
        phoneCnt: undefined,
        wxVideoCnt: undefined,
        ipVideoCnt: undefined,
        wifiVideoCnt: undefined,
        wxPhoneCnt: undefined,
        ipPhoneCnt: undefined,
        wifiPhoneCnt: undefined,
        ecpmMin: undefined
      }
      this.resetForm('form')
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs['form'].validate(valid => {
        if (valid) {
          updateIncomeConfig(this.form).then(response => {
            this.$modal.msgSuccess('修改成功')
            this.getList()
          })
        }
      })
    }
  }
}
</script>
